//
// Created by ziya on 2021/10/18.
//

#ifndef THREAD_POOL_TASKPOOL_H
#define THREAD_POOL_TASKPOOL_H

#include "../../include/common.h"
#include "../../thread/hpp/Task.h"
class TaskPool {
private:
    int     _task_count;
    Task*    _tasks;
public:
    pthread_mutex_t _lock[1];
    pthread_cond_t  _condt[1];

    TaskPool(){
        _tasks = 0;

        assert( pthread_mutex_init(_lock,NULL) ==0,"mutex init fail");

        assert(pthread_cond_init(_condt,NULL) ==0,"mutex init fail");

    }

    int task_count(){
        return _task_count;
    }

    void AddTask(Task* node);

    Task* DequeueTask();

    void DequeueSpecificTask(Task* node);

    void DescTaskCount(){
        _task_count--;
    }

    void IncTaskCount(int step){
        _task_count += step;
    }

};


#endif //THREAD_POOL_TASKPOOL_H
